package state;

import com.sun.org.apache.bcel.internal.generic.NEW;

// 测试线程优先级  1-10，超出就抛出异常
// 线程优先级低，获取调度概率低，但不一定一定在优先级高的后面执行，只是概率低、
// 线程默认优先级5
public class TestPriority {
    public static void main(String[] args) {
        //主线程默认优先级
        System.out.println(Thread.currentThread().getName() + "--->" + Thread.currentThread().getPriority());

        MyProiority myProiority = new MyProiority();
        Thread t1 = new Thread(myProiority);
        Thread t2 = new Thread(myProiority);
        Thread t3 = new Thread(myProiority);
        Thread t4 = new Thread(myProiority);
        Thread t5 = new Thread(myProiority);

        // 先设置优先级、再启动
        t1.start();
        t2.setPriority(1);
        t2.start();
        t3.setPriority(4);
        t3.start();
        t4.setPriority(Thread.MAX_PRIORITY);
        t4.start();
        t5.setPriority(Thread.MIN_PRIORITY);
        t5.start();

        /*
            main--->5
            Thread-0--->5
            Thread-3--->10
            Thread-1--->1
            Thread-2--->4
            Thread-4--->1
         */
    }

}
class MyProiority implements Runnable{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"--->"+Thread.currentThread().getPriority());
    }
}
